package com.slg.android.listenbook.biz.home.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.slg.android.listenbook.R;
import com.slg.android.listenbook.biz.home.moudle.Channel;

import java.util.List;

/**
 * User: Giotto
 * Date: 2015-03-25
 * Time: 16:02
 */
public class ChannelAdapter extends BaseAdapter {
    private List<Channel> mData;
    private Context mContext;

    public ChannelAdapter(List<Channel> data, Context context) {
        mData = data;
        mContext = context;
    }

    @Override
    public int getCount() {
        return mData.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ChannelViewHolder holder = null;
        if(convertView == null){
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_channel_list,parent,false);
            ChannelViewHolder viewHolder = new ChannelViewHolder();
            viewHolder.name = (TextView) convertView.findViewById(R.id.item_channel_name);
            viewHolder.selected = convertView.findViewById(R.id.item_channel_selected);
            convertView.setTag(viewHolder);
        }
        holder = (ChannelViewHolder) convertView.getTag();
        Channel channel = mData.get(position);
        if(channel.isSelected()){
            holder.selected.setVisibility(View.VISIBLE);
        }else{
            holder.selected.setVisibility(View.INVISIBLE);
        }
        holder.name.setText(channel.getChannelName());
        return convertView;
    }

    public static class ChannelViewHolder{
        public View selected;
        public TextView name;

    }
}
